import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import { DNavBar } from '@/components'
import QRCode from 'qrcode'
import './index.scss'

export default class WxQrCode extends Component {
  componentDidMount() {
    const { payUrl } = this.$router.params

    if (payUrl) {
      QRCode.toCanvas(document.getElementById('canvas'), decodeURIComponent(payUrl), {
        width: 200,
        height: 200
      }, function (error) {
        if (error) throw new Error(error)
      })
    }
  }

  render() {
    return (
      <View className="wx_qr_code">
        <DNavBar title="微信支付"></DNavBar>
        <View className="code_container">
          <canvas id="canvas"></canvas>
        </View>
      </View>
    )
  }
}
